package javafx.demo.animation;

import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.RotateTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * 效果同时运行
 * 
 * @author flyfox
 * @date 2014年10月23日
 */
public class TestParallelTransition extends Application {

	private ParallelTransition parallelTransition;

	@Override
	public void start(Stage stage) throws Exception {
		Rectangle rectParallel = new Rectangle(10, 200, 50, 50);
		rectParallel.setArcHeight(15);
		rectParallel.setArcWidth(15);
		rectParallel.setFill(Color.DARKBLUE);
		rectParallel.setTranslateX(50);
		rectParallel.setTranslateY(75);

		FadeTransition fadeTransition = new FadeTransition(Duration.millis(3000), rectParallel);
		fadeTransition.setFromValue(1.0f);
		fadeTransition.setToValue(0.3f);
		fadeTransition.setCycleCount(2);
		fadeTransition.setAutoReverse(true);
		TranslateTransition translateTransition = new TranslateTransition(Duration.millis(2000), rectParallel);
		translateTransition.setFromX(50);
		translateTransition.setToX(350);
		translateTransition.setCycleCount(2);
		translateTransition.setAutoReverse(true);
		RotateTransition rotateTransition = new RotateTransition(Duration.millis(3000), rectParallel);
		rotateTransition.setByAngle(180f);
		rotateTransition.setCycleCount(4);
		rotateTransition.setAutoReverse(true);
		ScaleTransition scaleTransition = new ScaleTransition(Duration.millis(2000), rectParallel);
		scaleTransition.setToX(2f);
		scaleTransition.setToY(2f);
		scaleTransition.setCycleCount(2);
		scaleTransition.setAutoReverse(true);

		parallelTransition = new ParallelTransition();
		parallelTransition.getChildren().addAll(fadeTransition, translateTransition, rotateTransition, scaleTransition);
		parallelTransition.setCycleCount(Timeline.INDEFINITE);
		parallelTransition.play();

		BorderPane outerRoot = new BorderPane();
		outerRoot.setCenter(rectParallel);

		Scene scene = new Scene(outerRoot, 600, 500);

		stage.setTitle("Hello World!");
		stage.setScene(scene);
		stage.show();

	}

	public static void main(String[] args) {
		launch(args);
	}
}
